/* 
 * 
 * Created on 11 Nov 2011 by simonk
 * 
 * Copyright: Multicom Products Ltd. 2011 Bristol, England
 */
package filesystem;

import java.util.ArrayList;
import java.util.List;

import com.google.gson.Gson;

/**
 *
 * @author simonk
 */
public class CFile {
	private long id;
	private long parent;
	private String name;
	private String size;
	private String lastModified;
	private boolean isDirectory;
	private List<Long> children;
	
	public CFile() {	
	}
	
	public CFile(String name, String size, String lastModified, boolean isDir) {
		this.name = name;
		this.size = size;
		this.lastModified = lastModified;
		this.isDirectory = isDir;
		this.setChildren(new ArrayList<Long>());
	}
	
	public CFile(long id, long parent, String name, String size, String lastModified, boolean isDir) {
		this.setId(id);
		this.setParent(parent);
		this.name = name;
		this.size = size;
		this.lastModified = lastModified;
		this.isDirectory = isDir;
		this.setChildren(new ArrayList<Long>());
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public long getParent() {
		return parent;
	}

	public void setParent(long parent) {
		this.parent = parent;
	}

	public List<Long> getChildren() {
		return children;
	}

	public void setChildren(List<Long> children) {
		this.children = children;
	}
	
	public void addChild(CFile file) {
		children.add(file.getId());
	}
	
	public void removeChild(CFile file) {
		children.remove(file.getId());
	}
	
	public String toString()
	{
		return new Gson().toJson(this);
	}
	
	public static CFile fromJson(String json)
	{
		return new Gson().fromJson(json,CFile.class);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getSize() {
		return size;
	}

	public void setSize(String size) {
		this.size = size;
	}

	public String getLastModified() {
		return lastModified;
	}

	public void setLastModified(String lastModified) {
		this.lastModified = lastModified;
	}

	public boolean isDirectory() {
		return isDirectory;
	}

	public void setDirectory(boolean isDirectory) {
		this.isDirectory = isDirectory;
	}
}
